<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>小飞象-计划管理-新建计划</title>
    <link rel="stylesheet" href="//at.alicdn.com/t/font_810097_s50gcn082go.css">
    <link rel="stylesheet" href="../css/common/reset.css">
    <link rel="stylesheet" href="../layui/css/layui.css">
    <link rel="stylesheet" href="../css/reset-layui.css">
    <link rel="stylesheet" href="../css/header.css">
    <link rel="stylesheet" href="../css/common/nav.css">
    <link rel="stylesheet" href="../css/common/aside.css">
    <link rel="stylesheet" href="../css/common/content.css">
    <link rel="stylesheet" href="../css/planMage.css">
</head>

<body>
    <header>
        <div class="wrapper">
            <div class="clearfix headerBox">
                <h1 class="fl logo">
                    <a href="">小飞象</a>
                </h1>
                <!-- <div class="fl alipayName">支付宝充值账号: <b class="redColor">156****8656</b>开户人: <b class="redColor">陈小窝</b></div> -->
                <div class="fr logOut">退出</div>
                <div class="fr userName"></div>
            </div>
        </div>
    </header>
    <div class="mhNav">
        <ul class="navMenuBox">
            <li>
                <a href="../index.html">
                    飞象首页
                </a>
            </li>
            <li>
                <a href="javascript:;">
                    会员中心
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="../member/basicInfo.html">基本资料</a>
                    </li>
                    <li>
                        <a href="../member/storeMage.html">店铺管理</a>
                    </li>
                    <li>
                        <a href="../member/readjustNum.html">调整单量</a>
                    </li>
                    <li>
                        <a href="/goodsMage.html">商品管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;" class="active">
                    计划管理
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="newPlan.html">新建计划</a>
                    </li>
                    <li>
                        <a href="planMage.html">计划管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    订单管理
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="../order/orderMage.html">订单管理</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="javascript:;">
                    资金管理
                </a>
                <ul class="mhColumnSide">
                    <li>
                        <a href="../capital/inAccout.html">账号充值</a>
                    </li>
                    <li>
                        <a href="../capital/transferMage.html">转账管理</a>
                    </li>
                    <li>
                        <a href="../capital/orderMage/dailyTaskDes.html">订单信息</a>
                    </li>
                    <li>
                        <a href="../capital/expressForm.html">获取快递底单</a>
                    </li>
                </ul>
            </li>
            <li>
                <a href="">在线客服</a>
            </li>
        </ul>
    </div>
    <div class="clearfix wrapper mainBomContent">
        <div class="asideMenu">
            <h2 class="title">
                <i class="iconfont icon--"></i> 计划管理
            </h2>
            <ul>
                <li>
                    <a href="../plan/newPlan.html">新建计划</a>
                </li>
                <li class="active">
                    <a href="../plan/planMage.html">计划管理</a>
                </li>
            </ul>
        </div>
        <div class="rightContent">
            <div class="planMageView">
                <form class="layui-form">
                    <!-- <input type="hidden" id="merchantsId" /> -->
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">计划类型：</label>
                            <div class="layui-input-inline">
                                <select name="" id="planType">
                                    <option value="">请选择</option>
                                    <option value="1">日常计划</option>
                                    <option value="2">指定计划</option>
                                    <option value="3">复购计划</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label w104">任务/订单编号：</label>
                            <div class="layui-input-inline w150">
                                <input type="text" placeholder="请填写任务/订单编号" id="taskNum" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">商品信息：</label>
                            <div class="layui-input-inline w120">
                                <input type="text" placeholder="请填写商品信息" id="goodsTitle" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">流量入口：</label>
                            <div class="layui-input-inline w155">
                                <select name="" id="goodsSearch">
                                    <option value="">请选择</option>
                                    <option value="1">淘宝APP自然搜索（手机端）</option>
                                    <option value="2">淘宝PC端自然搜索</option>
                                    <option value="3">淘宝APP淘口令</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline w64">
                                <button class="layui-btn" lay-submit="" lay-filter="searchPlan">搜索</button>
                            </div>
                        </div>
                    </div>
                </form>
                <table class="layui-table">
                    <colgroup>
                        <col width="200">
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>任务类型</th>
                            <th>任务/订单编号</th>
                            <th>商品信息</th>
                            <th>流量入口</th>
                            <th>开始时间</th>
                            <th>结束时间</th>
                            <th>操作按钮</th>
                        </tr>
                    </thead>
                    <tbody class="planInfo">
                        <!-- <tr>
                            <td>指定</td>
                            <td>0163676747647</td>
                            <td>陈小窝干嘛呢</td>
                            <td>淘宝APP自然搜索（手机端）</td>
                            <td>
                                <a href="javascript:void(0)" class="delBtn fDel">
                                    删除</a>
                            </td>
                        </tr> -->
                    </tbody>
                </table>
                <div class="loadMore">
                    <button id="loadMore">加载更多</button>
                </div>
            </div>
        </div>
    </div>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.cookie.js"></script>
    <script src="../layui/layui.js"></script>
    <script src="../js/dataRequest.js"></script>
    <script src="../js/timechange.js"></script>
    <script>
        var mid = $.cookie('id');
        console.log("你是我的商户ID", mid);
        if (mid == null || mid == "" || !mid || mid == undefined) {
            window.location.href = "/login.html";
        }
        $(".mhNav .navMenuBox > li > a").click(function (event) {
            if ($(this).siblings('ul').is(':visible')) {
                $(this).siblings('ul').stop(true, true).slideUp();
                $(this).removeClass('active')
            } else {
                $(this).siblings('ul').stop(true, true).slideDown().parents('li').siblings().find('ul').stop(
                    true, true).slideUp();
                $(this).addClass('active').parents('li').siblings().find('a').removeClass('active');
            }
        });
        layui.use(['form', 'layer'], function () {
            var layer = layui.layer,
                form = layui.form;
            var pageNum = 1; //当前页码
            var pageSize = 5; //每页显示数
            orderList();
            var _data = [];
            function orderList(status = 0) {
                var strVal = '';
                if (status == 1) {
                    var planType = $("#planType option:selected").val();
                    console.log("计划类型选择", planType);
                    var taskNum = $('#taskNum').val();
                    var goodsTitle = $('#goodsTitle').val();
                    var goodsSearch = $("#goodsSearch option:selected").val();

                    if (planType) {
                        strVal += '&planType=' + planType;
                    }
                    if (taskNum) {
                        strVal += '&taskNum=' + taskNum;
                    }
                    if (goodsTitle) {
                        strVal += '&goodsTitle=' + goodsTitle;
                    }
                    if (goodsSearch) {
                        strVal += '&goodsSearch=' + goodsSearch;
                    }
                }
                $.ajax({
                    url: BASE_URL + MAP_URL + "/plan/" + pageNum + "/" + pageSize +
                        "/?merchantsId=" + mid + strVal,
                    // url: 'http://47.92.174.143:8888/v1/client/plan/1/5/',
                    type: 'GET',
                    dataType: 'json',
                    contentType: "application/json;charset=utf-8",
                    success: function (data) {
                        console.log("qingqiudaoshenmmele：", data)
                        var _Success = data.code;
                        if (_Success == 200) {
                            var planHtml = "";
                            _data = data.data.list;
                            console.log("你好数据", _data);
                            if (_data.length == 0) {
                                console.log(123);
                                $("#loadMore").parent().addClass("noload");
                                $("#loadMore").attr("disabled", true);
                                $("#loadMore").html("没有数据拉");
                                $("#loadMore").css("cursor", "not-allowed");
                            }
                            if (pageNum == 1 && data.data.list.length == 0) {
                                $(".planInfo").html("暂无数据");
                                return;
                            }
                            // $("#merchantsId").val(_data[0].merchantsId);
                            for (var i = 0; i < data.data.list.length; i++) {
                                var planType;
                                switch (planType = _data[i].planType) {
                                    case 1:
                                        planType = "日常计划"
                                        break;
                                    case 2:
                                        planType = "指定计划"
                                        break;
                                    default:
                                        planType = "复购计划"
                                        break;
                                }
                                var goodsSearch;
                                switch (goodsSearch = _data[i].goodsSearch) {
                                    case 1:
                                        goodsSearch = "淘宝APP自然搜索（手机端）"
                                        break;
                                    case 2:
                                        goodsSearch = "淘宝PC自然搜索"
                                        break;
                                    default:
                                        goodsSearch = "淘宝APP淘口令"
                                        break;
                                }
                                planHtml += '<tr>';
                                planHtml += '<td class="planType">' + planType +
                                    '</td>';
                                planHtml += '<td class="taskNum">' + _data[i].taskNum + '</td>';
                                planHtml += '<td>' + _data[i].goodsTitle + '</td>';
                                planHtml += '<td class="goodsSearch">' + goodsSearch + '</td>';
                                planHtml += '<td>' + $.time.getTime(_data[i].planStartTime) + '</td>';
                                planHtml += '<td>' + $.time.getTime(_data[i].planEndTime) + '</td>';
                                planHtml += '<td><a href="javascript:void(0);" class="delBtn fDel" data-id=' + i +
                                    ' val="' + _data[i].id + '">删除</a>';
                                planHtml += '</td>';
                                planHtml += '</tr>';
                            }
                            $(".planInfo").append(planHtml);
                            $(".fDel").on("click", function (e) {
                                var planDelId = $(this).attr("val");
                                console.log("拿到的当前数据的id", planDelId);
                                layer.open({
                                    type: 2 //此处以iframe举例
                                    ,
                                    title: '删除',
                                    area: ['500px', '162px'],
                                    shadeClose: true //开启遮罩关闭
                                    ,
                                    offset: 'auto',
                                    scrollbar: true,
                                    content: ['delPlan.html', 'no'],
                                    success: function (layero, index) {
                                        var iframe = window['layui-layer-iframe' + index];
                                        iframe.child(planDelId);
                                    },
                                    zIndex: layer.zIndex //重点1
                                });
                            });
                        } else {
                            return;
                            layer.msg(data.data);
                        }
                    }
                })
            }
            form.on('submit(searchPlan)', function (data) {
                $(".layui-table tbody").html("");
                pageNum = 1;
                orderList(1);
                return false;
            });
            $("#loadMore").on("click", function () {
                pageNum++;
                orderList(1);
            });
        });
        $.ajax({
            type: "get",
            url: BASE_URL + MAP_URL + "/merchants/" + mid,
            dataType: 'json',
            success: function (data) {
                // console.log("请求数据为", data.data)
                // 存储总额
                if (data.data == null || !data.data) {
                    layer.msg('数据出错,请重新登录', {
                        icon: 5,
                        time: 6000,
                        end: function () {
                            location.href = '/login.html';
                        }
                    });
                } else {
                    $(".userName").html(data.data.loginId);
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) { }
        });
        //console.log("你是谁");
        // $(".fDel").live("click", function (e) {
        //     console.log("来了么")
        //     var _this = $(this);
        //     var planId = $(this).attr("data-id");
        //     // console.log("planId", planId);
        //     $.ajax({
        //         type: "DELETE",
        //         url: BASE_URL + MAP_URL + "plan/" + planId,
        //         //data:{planId: planId},
        //         dataType: 'json',
        //         success: function (data) {
        //             console.log("data", data)
        //             layer.msg('', {
        //                 time: 20000, //20s后自动关闭
        //                 btn: ['明白了', '知道了', '哦']
        //             });
        //             // return;
        //             _this.parent("td").parent("tr").remove();
        //         },
        //         error: function (XMLHttpRequest, textStatus, errorThrown) { }
        //     });
        // });
    </script>
</body>

</html>